package com.bw.user_module.forget;

import android.os.Bundle;
import android.text.TextUtils;

import androidx.databinding.ObservableField;

import com.bw.common.mvvm.viewmodel.BaseViewModel;
import com.bw.common.utils.ToastShowUtils;
import com.bw.network_sdk.BaseEntity;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class ForgetViewModel extends BaseViewModel<ForgetRespository> {

    public ObservableField<String>phone=new ObservableField<>();
    public ObservableField<String>timeStr=new ObservableField<>();
    public ObservableField<String>verify=new ObservableField<>("123456");

    public void next(){

    }

    public void verify(){

    }

    public void forget(){
        if (TextUtils.isEmpty(phone.get())){
            ToastShowUtils.showShort("请输入手机号");
            return;
        }
        if (TextUtils.isEmpty(verify.get())){
            ToastShowUtils.showShort("请输入验证码");
            return;
        }
        Map<String,Object>map=new HashMap<>();
        map.put("mobile",phone.get());
        map.put("verifyCode",verify.get());
        respository.requestForget(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(this);
    }

    @Override
    public void onResult(BaseEntity entity) {
        if (entity instanceof ForgetEntity){
            //找回成功->重置密码界面
//            startPage("/user/resetactivity");
            Bundle bundle = new Bundle();
            bundle.putString("phone",phone.get());
            startBundPage("/user/resetactivity",bundle);
        }
    }

    @Override
    protected void initData() {

    }
}
